// Demonstrates command line argument passing to a module.
#include <linux/module.h>
#include <linux/moduleparam.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/stat.h>
#include <linux/limits.h>

MODULE_LICENSE("GPL");
MODULE_AUTHOR("Dinosauria");

static short int myshort = SHRT_MAX;
static int myint = INT_MAX;
static long int mylong = LONG_MAX;
static char *mystring = "dinosuar";
static int myintArray[3] = { -1, 1 };
static int arr_argc = 0;


module_param(myshort, short, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);
MODULE_PARM_DESC(myshort, "A short integer");
module_param(myint, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
MODULE_PARM_DESC(myint, "An integer");
module_param(mylong, long, S_IRUSR);
MODULE_PARM_DESC(mylong, "A long integer");
module_param(mystring, charp, 0000);
MODULE_PARM_DESC(mystring, "A character string");

module_param_array(myintArray, int, &arr_argc, 0400);
MODULE_PARM_DESC(myintArray, "An array of integers");

static int __init mykmod_init(void)
{
    int i;
    printk(KERN_INFO "Hello, Dinosauria !\n=============\n");
    printk(KERN_INFO "my short integer: %hd\n", myshort);
    printk(KERN_INFO "my integer: %d\n", myint);
    printk(KERN_INFO "my long integer: %ld\n", mylong);
    printk(KERN_INFO "my string: %s\n", mystring);
    for (i = 0; i < (sizeof myintArray / sizeof (int)); i++)
    {
        printk(KERN_INFO "myintArray[%d] = %d\n", i, myintArray[i]);
    }
    printk(KERN_INFO "got %d arguments for myintArray.\n", arr_argc);
    return 0;
}

static void __exit mykmod_exit(void)
{
    printk(KERN_INFO "Goodbye, Dinosauria\n");
}

module_init(mykmod_init);
module_exit(mykmod_exit);